<!--
 * @Author: windys
 * @Description: 直播支付
 * @Date: 2022-02-15 13:35:28
-->
<template>
  <van-overlay :show="show">
    <div class="wrapper">
      <van-icon name="cross" class="close" @click.stop="show = false" />
      <van-image
        width="30"
        height="30"
        :src="item.headUrl"
        round
        style="margin-top: 20px"
      />
      <span class="spName">{{ item.spName }}</span>
      <van-image width="350" height="180" radius="8px" :src="item.coverUrl" />
      <div class="live_detail">
        <span>直播简介：{{ item.describe }}</span>
        <span v-if="item.isPayed == 2">有效时间：{{ item.validDateTo }}</span>
      </div>

      <div class="footer">
        <van-button
          type="primary"
          round
          size="small"
          color="#ddb888"
          @click="handlePay"
          >金石支付({{
            item.vipStatus > 0
              ? item.price + "金石"
              : item.originPrice + "金石"
          }})</van-button
        >
      </div>
    </div>
  </van-overlay>

  <van-action-sheet v-model:show="showSend" title="购买赠送">
    <div class="content">
      <div class="item" v-for="item in list " :key="item.id">
        <div class="left">
          <van-image :src="item.coverUrl" width="120" height="70" radius="5px" fit="contain"  />
        </div>
        <div class="right">
          <div class="title">{{item.goodsName}}</div>
          <div class="sp">
            <van-image :src="item.headUrl" width="25" height="25" round fit="contain"  />
            <span>{{item.spName}}</span>
          </div>
          <span class="time">{{item.days}}有效期</span>
        </div>
      </div>
    </div>
  </van-action-sheet>
</template>



<script >
import { defineComponent, onMounted, ref, watch } from "vue";
import { payLive, getSendGoodsList } from "@/api/live";
import { useRouter } from "vue-router";
import { useStore } from "@/store";

export default defineComponent({
  setup() {
    const store = useStore();
    const show = ref(false);
    const showSend = ref(false);
    const item = ref({});
    const router = useRouter();
    const handlePay = async () => {
      const res = await payLive({
        liveId: item.value.liveId,
        csTabId: item.value.csTabId,
      });
      if (typeof res === "string") {
        show.value = false;
        router.push({
          path: "/liveroom",
          query: {
            liveId: item.value.liveId,
            chatRoomId: item.value.chatRoomId,
            randomNum: Math.random().toFixed(6).slice(-6),
          },
        });
      }
      if (res === 1011) {
        store.openRecharge();
      }
    };

    watch(
      () => show.value,
      (v) => {
        if (v) {
          initSendData();
        } else {
          showSend.value = false;
        }
      }
    );

    const list = ref([]);
    const initSendData = async () => {
      const res = await getSendGoodsList({
        subjectId: item.value.liveId,
        pageIndex: 1,
        pageSize: 10,
      });
      if (res && res.length) {
        list.value = res;
        showSend.value = true;
      }
    };
    return {
      list,
      show,
      showSend,
      item,
      handlePay,
    };
  },
});
</script>


<style lang="scss" scoped>
.wrapper {
  height: 100%;
  background-image: linear-gradient(#403747, #4b5369);
  opacity: 0.9;
  position: relative;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  .close {
    position: absolute;
    top: 10px;
    right: 10px;
    color: #fff;
  }
  .spName {
    font-size: 14px;
    margin: 10px 0;
  }
  .live_detail {
    font-size: 12px;
    width: 82%;
    text-align: left;
    display: flex;
    flex-direction: column;
    margin: 20px 0;
  }
  .footer {
    position: absolute;
    bottom: 30px;
    button {
      margin: 0 20px;
    }
  }
}
.content {
  min-height: 100px;
  max-height: 300px;
  overflow-y: auto;
  margin-top: 10px;
  margin-bottom: 20px;
  .item{
    display: flex;
    font-size: 12px;
    margin: 5px 10px;
    height: 70px;
    position: relative;
    .left{
      width: 120px;
      text-align: center;
    }
    .right{
      width: calc(100% - 120px);
      .title{
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 14px;
      }
      .sp{
        display: flex;
        height: 30px;
        line-height: 25px;
        margin-top: 10px;
        span{
          color: #999;
          margin-left: 10px;
        }
      }
    }
    .time{
      position: absolute;
      right: 0;
      top: 30px;
      border: 1px solid #ff9900;
      padding: 4px 8px;
      border-radius: 15px;
      font-size: 10px;
      color: #ff9900;
    }
  }
}
</style>